package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.ISystemNoticeService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/travel")
public class TravelController {
    @Autowired
    private ITravelService travelService;
    @Autowired
    private ISystemNoticeService systemNoticeService;
    @RequestMapping("list")
    public String list(@ModelAttribute("qo") TravelQueryObject qo, Model model){
        qo.setIsPublic(true);
        qo.setOrderBy("t.lastUpdateTime");
        if(qo.getState()==null){
            qo.setState(1);
        }
        PageInfo pageInfo = travelService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "/travel/list";
    }
    @RequestMapping("/changeStatus")
    @ResponseBody
    public JSONResult changeStatus(Travel travel){
        travelService.changeStatus(travel);
        systemNoticeService.addMessage(travel);
        return new JSONResult();
    }
    @RequestMapping("releaseList")
    public String releaseList(@ModelAttribute("qo") TravelQueryObject qo, Model model){
        qo.setIsPublic(true);
        qo.setOrderBy("t.releaseTime desc");
        qo.setState(2);
        PageInfo pageInfo = travelService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "/travel/releaseList";
    }

}
